package zjh_20230328;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

public class Demo02 {
    public static void main(String[] args) {
        //内省机制
        try {
            PropertyDescriptor propertyDescriptor = new PropertyDescriptor("name",Student.class);

            Method writeMethod = propertyDescriptor.getWriteMethod();
            Method readMethod = propertyDescriptor.getReadMethod();

            Class<Student> studentClass = Student.class;
            Student student = studentClass.newInstance();

            Object o = writeMethod.invoke(student, "二狗");
            System.out.println(o);

            Object invoke = readMethod.invoke(student);
            System.out.println(invoke);
            System.out.println(student);

        } catch (IntrospectionException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }

    }
}
